package com.csi.service.impl;

import com.csi.domain.FacilityInfo;
import com.csi.mapper.FacilityInfoMapper;
import com.csi.service.FacilityInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FacilityInfoServiceImpl implements FacilityInfoService {

    @Autowired
    private FacilityInfoMapper facilityInfoMapper;

    /**
     * 新增设施
     * @param facilityInfo
     * @return
     */
    @Override
    public int save(FacilityInfo facilityInfo) {

        int ret =  facilityInfoMapper.save(facilityInfo);

        return ret;
    }

    /**
     * 删除设施
     * @param id f
     * @return
     */
    @Override
    public int delete(long id) {

        FacilityInfo facilityInfo = facilityInfoMapper.findById(id);
        int ret = 0;
        if(facilityInfo.getFacilityType() == "房型"){
            ret =  facilityInfoMapper.Rdelete(facilityInfo.getId());
            ret =  facilityInfoMapper.delete(id);
        }else{
            ret =  facilityInfoMapper.delete(id);
        }
        return ret;
    }

    /**
     * 修改设施名称
     * @param facilityInfo
     * @return
     */
    @Override
    public int update(FacilityInfo facilityInfo) {
        int ret =  facilityInfoMapper.update(facilityInfo);
        return ret;
    }

    /**
     *查找单个
     * @param id
     * @return
     */
    @Override
    public FacilityInfo findById(long id) {
        FacilityInfo facilityInfo = facilityInfoMapper.findById(id);
        return facilityInfo;
    }

    /**
     * 查找全部
     * @return
     */
    @Override
    public List<FacilityInfo> findAll(long hotelId) {
        List<FacilityInfo> list = facilityInfoMapper.findAll(hotelId);
        return list;
    }
}
